<%@page contentType="text/html"%>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@page import="org.apache.taglibs.datagrid.DataGridParameters"%>

<html>
  <head>
     <title>Control</title>
  </head>
  <body>
       <%! public class control {
            protected String medicamento;
            protected String hora;
            protected String dosis;
            
            public String getmedicamento () {
                return (medicamento);
                  }
                     public String gethora (){
                        return (hora);
                      }      
                     public String getdosis () {
                        return (dosis);
                      }            
                      public void setmedicamento (String newmedicamento)
{
                                medicamento = newmedicamento;
                          }
                          public void sethora (String newhora)
                          {
                                hora = newhora;
                          }
                          public void setdosis (String newdosis)
                          {
                                dosis = dosis;
                          }
                                
                        }
        %>
        <%  ArrayList control = new ArrayList ();
           control  objcontrol;
             int fromIndex, toIndex;
              try {
                String connectionURL = "jdbc:postgresql://54.172.131.75:5432/telemedicina";
                    Connection connection = null;
                                Statement statement = null;
                ResultSet rs = null;
                Class.forName("org.postgresql.Driver").newInstance();
                connection = DriverManager.getConnection(connectionURL, 
                "postgres", "Xdr5tgb");
                statement = connection.createStatement();
                String QueryString = "SELECT medicamento,hora,dosis from control";
                rs = statement.executeQuery(QueryString);
                        while (rs.next()) {             
                        objcontrol = new control ();
                        objcontrol.setmedicamento(rs.getString("medicamento"));
                        objcontrol.sethora(rs.getString("hora"));
                        objcontrol.setdosis(rs.getString("dosis"));
                        control.add(objcontrol);
                }
                        rs.close();
                        statement.close();
                                        connection.close();
                                } 
    catch (Exception ex) {
            System.out.println("Unable to connect to batabase."+ex);
        }
   fromIndex = (int) DataGridParameters.getDataGridPageIndex (request, 
               "datagrid1");
   if ((toIndex = fromIndex+4) >= control.size ())
  toIndex = control.size();
   request.setAttribute ("control", control.subList(fromIndex, toIndex));
%>
   <style>
    th a:link      { text-decoration: none; color: black }
     th a:visited   { text-decoration: none; color: black }
     .rows          { background-color: white }
     .hiliterows    { background-color: #848484; color: white; 
                      font-weight: bold }
     .alternaterows { background-color: #D8D8D8 }
     .header        { background-color: #2E2E2E; color: #D8D8D8;font-weight: 
                      bold }
             .datagrid      { border: 1px solid #C7C5B2; font-family: arial; 
                      font-size: 9pt;
            font-weight: normal }
   </style>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <ui:dataGrid items="${control}" var="control" name="datagrid1" 
 cellPadding="0" 
    cellSpacing="0" styleClass="datagrid">
  <columns>
   <column width="50">
      <header value="Select" hAlign="center" styleClass="header"/>
     <item>
        
      <aggregate function="count" var="total"/>
          </item>
    </column>
    <column width="150">
      <header value="Name" hAlign="center" styleClass="header"/>
      <item   value="${control.medicamento} ${control.hora} ${control.dosis} " hAlign="left" 
             styleClass="item"/>
      <aggregate function="count" var="total"/>
         </columns>
    </columns>
  <rows          styleClass="rows" hiliteStyleClass="hiliterows"/>
  <alternateRows styleClass="alternaterows"/>
  <paging        size="4" count="11" custom="true" nextUrlVar="next" 
       previousUrlVar="previous" pagesVar="pages"/>
  <order         imgAsc="up.gif" imgDesc="down.gif"/>
</ui:dataGrid>
<table width="500" style="font-family: arial; font-size: 10pt">
<tr>
<td align="center" width="33%">
</tr>
</table>
</body>
</html>